<template>
  <div class="main-content">
    <el-carousel height="450px">
      <el-carousel-item v-for="item in imgs" :key="item">
        <img :src="item" alt="" style="width: 100%;border-radius: 5px 5px 0 0">
      </el-carousel-item>
    </el-carousel>

    <div style="margin: 30px 0">
      <div style="margin-bottom: 20px; display: flex; align-items: center">
        <div style="font-weight: bold; font-size: 22px; flex: 1">精选文艺作品</div>
        <a style="color: #2a60c9" href="/front/works">更多>></a>
      </div>
      <div>
        <el-row :gutter="10">
          <el-col :span="6" v-for="item in workList.slice(0, 4)" :key="item.id" >
            <div style="cursor: pointer " @click="goDetail('/front/workDetail?id='+ item.id)" >
              <img :src="item.cover" alt="" style="width: 100%; height: 150px; border-radius: 5px 5px 0 0">
              <div style="margin: 5px 0; font-size: 16px" class="line1">{{ item.name }}</div>
              <div style="display: flex; align-items: center">
                <img style="width: 30px; height: 30px; border-radius: 50%" :src="item.avatar" alt="">
                <span style="color: #666; margin-left: 10px">{{ item.userName }}</span>
              </div>
              <div style="margin-top: 5px;color: #666">发布时间:{{item.releaseTime}}</div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>

    <div style="margin: 30px 0">
      <div style="margin-bottom: 20px; display: flex; align-items: center">
        <div style="font-weight: bold; font-size: 22px; flex: 1">个人感悟</div>
        <a style="color: #2a60c9" href="/front/notebook">更多>></a>
      </div>
      <div>
        <el-row :gutter="10">
          <el-col :span="6" v-for="item in notebookList.slice(0, 4)" :key="item.id">
            <div style="cursor: pointer " @click="goDetail('/front/notebookDetail?id='+ item.id)">
              <img :src="item.cover" alt="" style="width: 100%; height: 200px; border-radius: 5px 5px 0 0">
              <div style="box-shadow: -3px 3px 3px -2px rgba(0,0,0,0.1), 3px 3px 3px -2px rgba(0,0,0,0.1); padding: 5px">
                <div style="margin-bottom: 10px; font-size: 16px" class="line1">{{ item.title }}</div>
                <div style="display: flex; align-items: center">
                  <img style="width: 30px; height: 30px; border-radius: 50%" :src="item.avatar" alt="">
                  <span style="color: #666; margin-left: 10px">{{ item.userName }}</span>
                </div>
                <div style="color: #666; margin-top: 10px">发布时间:{{item.releaseTime}}</div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
    <div style="margin: 30px 0">
      <div style="margin-bottom: 20px; display: flex; align-items: center">
        <div style="font-weight: bold; font-size: 22px; flex: 1">猜你喜欢</div>
      </div>
      <div>
        <el-row :gutter="10">
          <el-col :span="6" v-for="item in recommendWorkList" :key="item.id" >
            <div style="cursor: pointer " @click="goDetail('/front/workDetail?id='+ item.id)" >
              <img :src="item.cover" alt="" style="width: 100%; height: 150px; border-radius: 5px 5px 0 0">
              <div style="margin: 5px 0; font-size: 16px" class="line1">{{ item.name }}</div>
              <div style="display: flex; align-items: center">
                <img style="width: 30px; height: 30px; border-radius: 50%" :src="item.avatar" alt="">
                <span style="color: #666; margin-left: 10px">{{ item.userName }}</span>
              </div>
              <div style="color: #666; margin-top: 10px">发布时间:{{item.releaseTime}}</div>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="10" style="margin-top: 30px">
          <el-col :span="6" v-for="item in recommendNotebookList.slice(0, 4)" :key="item.id">
            <div style="cursor: pointer " @click="goDetail('/front/notebookDetail?id='+ item.id)">
              <img :src="item.cover" alt="" style="width: 100%; height: 200px; border-radius: 5px 5px 0 0">
              <div style="box-shadow: -3px 3px 3px -2px rgba(0,0,0,0.1), 3px 3px 3px -2px rgba(0,0,0,0.1); padding: 5px">
                <div style="margin-bottom: 10px; font-size: 16px" class="line1">{{ item.title }}</div>
                <div style="display: flex; align-items: center">
                  <img style="width: 30px; height: 30px; border-radius: 50%" :src="item.avatar" alt="">
                  <span style="color: #666; margin-left: 10px">{{ item.userName }}</span>
                </div>
                <div style="color: #666; margin-top: 10px">发布时间:{{item.releaseTime}}</div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>

  </div>
</template>

<script>

export default {

  data() {
    return {
      imgs: [
        require('@/assets/imgs/1.webp'),
        require('@/assets/imgs/2.jpg'),
        require('@/assets/imgs/3.jpg'),
      ],
      workList: [],
      notebookList: [],
      recommendWorkList:[],
      recommendNotebookList:[]
    }
  },
  mounted() {
    this.loadWorkList()
    this.loadNotebookList()
    this.loadRecommendWorkList()
    this.loadRecommendNotebookList()
  },
  // methods：本页面所有的点击事件或者其他函数定义区
  methods: {
    goDetail(path){
      location.href=path
    },
    loadNotebookList() {
      this.$request.get('/notebook/selectPage', { params: { status: '审核通过', pageSize: 4 } }).then(res => {
        this.notebookList = res.data?.list || []
      })
    },
    loadWorkList() {
      this.$request.get('/works/selectRecommend').then(res => {
        this.workList = res.data || []
      })
    },
    loadRecommendWorkList(){
      this.$request.get('/works/listRecommendWorks').then(res=>{
        this.recommendWorkList=res.data || []
      })
    },
    loadRecommendNotebookList(){
      this.$request.get('/notebook/listRecommendNotebook').then(res=>{
        this.recommendNotebookList=res.data || []
      })
    },
  }
}
</script>
